import type { ConsolaInstance, LogType } from 'consola'
import { consola } from 'consola'
import { lightGreen } from 'kolorist'

class Logger {
  private readonly logger: ConsolaInstance

  prefix: string

  constructor(prefix = lightGreen('[l-router]')) {
    this.logger = consola
    this.prefix = prefix
  }

  log(msg: string, type: LogType, show = true): void {
    if (!show)
      return

    this.logger[type](`${this.prefix} ${msg}`)
  }

  start(msg: string, show = true): void {
    this.log(msg, 'start', show)
  }

  info(msg: string, show = true): void {
    this.log(msg, 'info', show)
  }

  success(msg: string, show = true): void {
    this.log(msg, 'success', show)
  }

  warn(msg: string, show = true): void {
    this.log(msg, 'warn', show)
  }

  error(msg: string, show = true): void {
    this.log(msg, 'error', show)
  }

  table(data: any[], show = true): void {
    if (!show)
      return

    // eslint-disable-next-line no-console
    console.table(data)
  }
}

export const logger = new Logger()
